package com.sun.controller;

import com.sun.pojo.entity.PurchaseSettlement;
import com.sun.pojo.vo.R;
import com.sun.service.PurchaseSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 采购结算表(PurchaseSettlement)表控制层
 *
 * @author makejava
 * @since 2024-10-25 08:18:16
 */
@RestController
@RequestMapping("purchaseSettlement")
@CrossOrigin
public class PurchaseSettlementController {
    /**
     * 服务对象
     */
    @Autowired
    PurchaseSettlementService purchaseSettlementService;

    /**
     * 分页查询
     *
     * @param purchaseSettlement 筛选条件
     * @param pageNum      分页对象
     * @return 查询结果
     */
    @GetMapping
    public R queryByPage(PurchaseSettlement purchaseSettlement, Integer pageNum) {
        return R.success(purchaseSettlementService.queryByPage(purchaseSettlement, pageNum));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R queryById(@PathVariable("id") Integer id) {
        return R.success(purchaseSettlementService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param purchaseSettlement 实体
     * @return 新增结果
     */
    @PostMapping
    public R add(@RequestBody PurchaseSettlement purchaseSettlement) {
        return R.success(purchaseSettlementService.insert(purchaseSettlement));
    }

    /**
     * 编辑数据
     *
     * @param purchaseSettlement 实体
     * @return 编辑结果
     */
    @PutMapping
    public R edit(@RequestBody PurchaseSettlement purchaseSettlement) {
        return R.success(purchaseSettlementService.update(purchaseSettlement));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("{id}")
    public R deleteById(@PathVariable("id") Integer id) {
        return R.success(purchaseSettlementService.deleteById(id));
    }

}

